<?php
/**
 * Created by PhpStorm
 * author: bxm
 * Date: 2023/2/20
 * Time: 14:29
 */

namespace app\api\controller\system;

use app\admin\model\SystemAdmin;
use app\common\controller\ApiController;
use think\App;

header('Access-Control-Allow-Origin:*');
class Admin extends ApiController
{
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new SystemAdmin();
        $this->assign('auth_list', $this->model->getAuthList());
    }

    /**
     * Notes: 获取系统用户
     * author: bxm
     * Date: 2023/2/21
     * Time: 9:27
     * @return false|string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getSystemUserList()
    {
        try{
            if(!request()->isPost()){
                $data = array('code'=>1,'请求方式不正确','data'=>[]);

                return json_encode($data);
            }
            $post = request()->post();
            $this->yanzSigin($post);

            $auth_ids = $post['data']['auth_ids'] ?? '';
            if(!in_array($auth_ids,[1,7,8])){
                $data = array('code'=>1,'请求参数不在合理范围内','data'=>[]);
                return json_encode($data);
            }
            $data = $this->model->where('auth_ids',$auth_ids)->field('id,auth_ids,head_img,phone,status')->append(['status_text','auth_ids_text'])->select();
        }catch (\Exception $e){
            return json_encode(['code'=>1, 'msg'=>$e->getMessage()]);
        }



        return json_encode(['code'=>0,'操作成功','data'=>$data]);

    }
}